package com.juyu.miliao.api.controller;

import com.juyu.miliao.api.domain.CoinPrice;
import com.juyu.miliao.api.service.CoinPriceService;
import com.juyu.miliao.common.domain.CommonHead;
import com.juyu.miliao.common.domain.Subject;
import com.juyu.miliao.common.util.VerifyUtil;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 金币充值价格信息
 * 
 * @author wbf
 */
@RestController
@RequestMapping("/coinPrice")
public class CoinPriceController {
	@Resource
	CoinPriceService coinPriceService;

	@GetMapping()
	public List<CoinPrice> getCoinPriceList(HttpServletRequest request, Authentication token) {
        //应用Id,用来区分马甲包与线上包
		CommonHead com = VerifyUtil.verifyCommonHead(request);
		Subject subject = (Subject) token.getPrincipal();
		return coinPriceService.getCoinPriceList(com,subject.getId());
	}
    /**
     * 金币支付弹窗信息，马甲包专用
	 *
     * @param request
     * @return
     */
	@GetMapping("/payCoin")
	public List<CoinPrice> getPayCoinList(HttpServletRequest request) {
        //应用Id,用来区分马甲包与线上包
		CommonHead com = VerifyUtil.verifyCommonHead(request);
		return coinPriceService.getPayCoinList(com);
	}

	/**
	 *
	 * @param type
	 * @return
	 */
	@GetMapping("/{type}")
	public List<CoinPrice> getCoinPriceListByCoinType(@PathVariable("type") Integer type) {
		return coinPriceService.getCoinPriceListByCoinType(type);
	}

	@GetMapping("/window")
	public List<CoinPrice> getCoinPriceWindowList(HttpServletRequest request) {
		CommonHead com = VerifyUtil.verifyCommonHead(request);
		return coinPriceService.getCoinPriceWindowList(com);
	}

}
